/*
 * JaCoLiB
 * Copyright (C) 2008 Alessandro Serra
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package it.gashale.jacolib.process.cl;

import it.gashale.jacolib.core.JacolibError;
import it.gashale.jacolib.process.RemoteProcess;


public class CLProcess extends RemoteProcess {
	private int port;
	private String secret_string;
	
	public CLProcess(String process_command_name, String bin_paths, String options, String load_opt, 
					String startfile, String start_res, int port) {
		super(process_command_name, bin_paths, options, load_opt, startfile, start_res);
		this.port=port;
		this.secret_string=null;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int p) {
		port=p;
	}
	public String getSecretString() {
		return secret_string;
	}
	public void setSecretString(String v) {
		secret_string=v;
	}
	
	
	protected void post_init() throws JacolibError {
		this.writeIntoProcessInput("(defvar *host* \"localhost\")");
		this.writeIntoProcessInput("(defvar *port* "+getPort()+")");
		this.writeIntoProcessInput("(defvar *secret-string* \""+this.getSecretString()+"\")");
		this.writeIntoProcessInput("(defvar *jacolib* (make-instance 'jacolib:jacolib))");
		this.writeIntoProcessInput("(format t \"launch jacolib client with arguments: ~A ~A ~A ~%\" *host* *port* *secret-string*)");
		this.writeIntoProcessInput("(jacolib:jacolib-connect-and-loop *jacolib* \"java\" *host* *port* *secret-string*)");
		this.writeIntoProcessInput("(quit)");
	}
	

}
